<template>
	<view>
		<z-nav-bar class="nav-bar" title="赚取积分" transparentTitle="auto" :isBlack="false">
			<template #right>
				<navigator url="/pages/student/score/rule" hover-class="none">规则</navigator>
			</template>
		</z-nav-bar>
		<!-- #ifdef MP-WEIXIN -->
		<view class="top" style="padding-top: calc(var(--status-bar-height) + 200rpx)">
		<!-- #endif -->
		<!-- #ifdef APP-PLUS || H5 -->
		<view class="top" :style="{ 'padding-top': `${navBarHeight}px` }">
		<!-- #endif -->
			<view class="text">我的积分</view>
			<view class="num">{{ signInfo.integral }}</view>
			<view class="flex_sbc" style="width: 700rpx">
				<navigator class="btn" hover-class="none" url="/pages/my/integral/list">
					积分明细
					<image :src="`${setting.sImgUrl}/index/fanhui_next@2x.png`"></image>
				</navigator>
				<view class="uni-white" @click="signInNow">{{ signInfo.isSign ? '已签到' : '立即签到' }}</view>
			</view>
			<view class="sign">
				<view class="title">
					已连续签到
					<text>{{ signInfo.signCount }}</text>
					天
				</view>
				<view class="box">
					<view class="line"></view>
					<view class="entry" @click="signInNow">
						<view class="row" v-for="(v, k) in day">
							<view :class="['add_num', v.old, 'active']" v-if="v.sign">
								<image :src="`${setting.sImgUrl}/score/click.png`"></image>
								<!-- <text>+{{ v.num }}</text> -->
							</view>
							<view :class="['add_num', v.old]" v-else></view>
							<view>{{ v.text }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="exchange">
			<view class="title">充值兑换</view>
			<view class="row">
				<view class="left">
					<image :src="`${setting.sImgUrl}/score/icon@2x(7).png`"></image>
					<view>
						<view>兑换积分</view>
						<view class="rate">比例 1:100</view>
					</view>
				</view>
				<navigator class="" hover-class="none" url="/pages/student/score/recharge">
					<view class="right">去兑换</view>
				</navigator>
			</view>
		</view> -->
		<view class="get_score">
			<view class="title">做任务赢积分</view>
			<view class="entry">
				<view v-for="(data, index) in taskList" :key="index">
					<view class="part">
						<view class="left">
							<image :src="`${setting.sImgUrl}/score/${data.type}.png`"></image>
							<view>
								<view>{{ data.name }}</view>
								<view class="text">
									<text>{{ data.integralDesc }}</text>
									<image :src="`${setting.sImgUrl}/score/arr.png`"></image>
								</view>
							</view>
						</view>
						<view v-if="data.status" class="right active">已经获取</view>
						<view v-else>
							<navigator
								v-if="data.path"
								:url="data.path"
								:open-type="data['open-type'] || 'navigate'"
								class="right"
								hover-class="none"
							>
								去完成
							</navigator>
							<view v-else-if="data.funName" class="right" @click="data.funName()">去完成</view>
							<view v-else class="right">去完成</view>
						</view>
					</view>
					<view v-if="data.remark" class="content">{{ data.remark }}</view>
				</view>
			</view>
		</view>
		<view style="height: 40rpx"></view>
	</view>
</template>

<script>
import { getSignCount, signNow, signTaskList, appShareScuess } from '@/api/student';
export default {
	data() {
		return {
			day: [
				{
					text: '第一天',
					sign: false,
					num: 0,
					old: ''
				},
				{
					text: '第二天',
					sign: false,
					num: 3,
					old: ''
				},
				{
					text: '第三天',
					sign: false,
					num: 3,
					old: ''
				},
				{
					text: '第四天',
					sign: false,
					num: 3,
					old: ''
				},
				{
					text: '第五天',
					sign: false,
					num: 3,
					old: ''
				},
				{
					text: '第六天',
					sign: false,
					num: 3,
					old: ''
				},
				{
					text: '第七天',
					sign: false,
					num: 3,
					old: ''
				}
			],
			navBarHeight: 0,
			signInfo: {},
			taskList: []
		};
	},
	mounted() {
		uni.createSelectorQuery()
			.select('.nav-bar')
			.boundingClientRect((data) => {
				this.navBarHeight = data.height;
			})
			.exec();
	},
	onShow() {
		getSignCount().then((res) => {
			this.signInfo = res;
			for (let i = 1; i <= res.signCount; i++) {
				if (!this.day[i - 1]) continue
				this.day[i - 1].sign = true;
				this.day[i - 1].old = 'old';
			}
		});
		signTaskList().then((res) => {
			const obj = [
				{ type: 'sign' },
				{ type: 'info', path: '/pages/my/personal-setting/personal-setting' },
				{ type: 'file' },
				{ type: 'course', path: '/pages/student/course/entry?type=1' },
				{ type: 'coach', path: '/pages/tabbar-page/tabbar-0', 'open-type': 'switchTab' },
				{ type: 'qs', path: '/pages/student/course/entry?type=2' },
				{ type: 'share', funName: this.shareFun }
			];
			res.forEach((item, index) => {
				Object.assign(item, obj[index]);
			});
			this.taskList = res;
		});
	},
	methods: {
		signInNow() {
			signNow().then((res) => {
				if (this.signInfo.signCount == 7) {
					this.signInfo.signCount = 1;
					this.day[0].sign = true;
				} else {
					this.signInfo.signCount += 1;
					this.day[this.signInfo.signCount - 1].sign = true;
				}
				this.tools.alert('签到成功');
			});
		},
		shareFun() {
			uni.share({
				provider: 'weixin',
				scene: 'WXSceneSession',
				type: 5,
				imageUrl: 'http://golfpub.jgtygolf.com/app-img/logo.png',
				title: '降杆教育',
				miniProgram: {
					id: 'gh_6be15b82eac6',
					webUrl: 'http://golfpub.jgtygolf.com/app-img/logo.png',
					type: 1
				},
				success: (ret) => {
					appShareScuess();
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
@import './css/score.scss';
</style>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>
